class Widget < ActiveRecord::Base
  has_many :hub_widgets
  
  has_many :code_files do
    def widget_view
      find(:first, :conditions => {:name => "widget", :view => true})      
    end
    
    def background
      find(:first, :conditions => {:name => "background", :view => false})      
    end
  end
  
  def invalidate_cache!
    HubWidget.update_all("cache = NULL", "widget_id = #{self.id}")
  end  
end
